import random, time
setGlobalDuration(30)

beginPythonInst(1)
soundfont(duration=4)
endPythonInst()

proc = startCsound()

scl = scale('Em')

rnd = loopseg(25,35)

time.sleep(2)
patterns = [[4,2,2,1,1], [3,2,2,3], [2,1,1,1,1,2,1,1], [4,1,1,1,1,1,1]]

def pit():
    if ti1.getBeat() == 1 and (ti1.getBar() % 4) == 0:
        ti1.changePattern(random.choice(patterns))
    dict = {'soundfont': {}}
    dict['soundfont']['midipitch'] = scl[rnd.next()]
    dict['soundfont']['pan'] = random.randint(0,7)*0.125
    sendEvent(1, dict, proc)

ti1 = pattern(.125, pit, [3,3,2,2])
ti1.start()
ti1.play()


